package myrectangle9_1_2_6;

public class MyRectangle {
	private MyPoint leftUpper;
	private MyPoint rightLower;

	public MyRectangle(MyPoint leftUpper, MyPoint rightLower) {
		super();
		this.leftUpper = leftUpper;
		this.rightLower = rightLower;
	}

	public MyPoint getLeftUpper() {
		return leftUpper;
	}

	public void setLeftUpper(MyPoint leftUpper) {
		this.leftUpper = leftUpper;
	}

	public MyPoint getRightLower() {
		return rightLower;
	}

	public void setRightLower(MyPoint rightLower) {
		this.rightLower = rightLower;
	}

	public double getPerimeter() {
		int a = Math.abs(leftUpper.getX() - rightLower.getX());
		int b = Math.abs(leftUpper.getY() - rightLower.getY());
		return 2 * (a + b);
	}

	public double getDiagonal() {
		return leftUpper.distance(rightLower);
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return leftUpper.hashCode() + rightLower.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		if(!(obj instanceof MyRectangle))
			return false;
		MyRectangle myRectangle = (MyRectangle) obj;
		return this.leftUpper == myRectangle.leftUpper && this.rightLower == myRectangle.rightLower;
	}

	@Override
	public String toString() {
		return "MyRectangle [leftUpper=" + leftUpper + ", rightLower=" + rightLower + "]";
	}


	
}
